package com.sjx.boundarycallback.ui;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;

import com.sjx.boundarycallback.R;
import com.sjx.boundarycallback.adapter.RecyclerAdapter;
import com.sjx.boundarycallback.databinding.ActivityRecyclerViewBinding;
import com.sjx.boundarycallback.decoration.BitMapItemDecoration;

import java.util.ArrayList;

/**
 * created sjx by 2022/05/31
 * 展示RecyclerView的activity
 */
public class RecyclerViewActivity extends AppCompatActivity {

    private ActivityRecyclerViewBinding mBinding;
    private ArrayList<String> dataList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initData();
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_recycler_view);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mBinding.recyclerView.setLayoutManager(linearLayoutManager);
//        LinearItemDecoration mDivider = new LinearItemDecoration();
        BitMapItemDecoration mDivider = new BitMapItemDecoration(this);
        mBinding.recyclerView.addItemDecoration(mDivider);
        RecyclerAdapter mAdapter = new RecyclerAdapter(dataList);
        mBinding.recyclerView.setAdapter(mAdapter);

    }

    private void initData() {
        dataList = new ArrayList<>();
        for (int i = 0; i < 30; i++) {
            dataList.add("第" + i + "个item");
        }
    }
}